package cn.daniellee.plugin.vs.runnable;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;

import java.util.HashMap;
import java.util.Map;
import java.util.Queue;

public class VisitorsRunnable extends BukkitRunnable {

    public static HashMap<String, Queue<Location>> visitors = new HashMap<>();

    @Override
    public void run() {
        for (Map.Entry<String, Queue<Location>> entity : visitors.entrySet()) {
            Queue path = entity.getValue();
            if (path.isEmpty()) {
                visitors.remove(entity.getKey());
            } else {
                Player player = Bukkit.getPlayer(entity.getKey());
                if (player != null) {
                    Location location = (Location) path.poll();
                    player.teleport(location);
                }
            }
        }

    }

}
